﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Net.Mail;

namespace TwoGesture.Resources
{
    public partial class AgregarCategoria : Form
    {

        private static AgregarCategoria objAgrCategoria = null;
        private AgregarPregunta objAgrpregunta = AgregarPregunta.singleton();
        private FormAdmin objFormAdmin = FormAdmin.singleton();
        private ControlAdministrador ObjCtrAdministrador = ControlAdministrador.InsCtrAdministrador();
        private ControlPregunta ObjCtrPregunta = ControlPregunta.InsControlPregunta();
        private ControlTest objCtrTest = ControlTest.insControlTest();
        private ControlCrearCuest objCtrCuest= ControlCrearCuest.instCrearCuest();
        private string contra = "";
        private string valor = string.Empty;
        private string banderausuario = string.Empty;

        public AgregarCategoria()
        {
            InitializeComponent();

        }

        public AgregarCategoria(string valor_)
        {
            valor = valor_;
            InitializeComponent();
        }

        private void AgregarCategoria_Load(object sender, EventArgs e)
        {
            this.llenarTablaTest();
            this.LblIdDoctor.Text = objFormAdmin.LblIdDoctor.Text;
        }

       
        private static AgregarCategoria singleton()
        {
            if (objAgrCategoria == null)
            {
                objAgrCategoria=new AgregarCategoria();
            }

            return objAgrCategoria;
        }


        //--------------------------------------------------------------------------------
        //-----------------------Formulario Agragar Test------------------------------
        //--------------------------------------------------------------------------------
      
        private void llenarTablaTest()
        {
            SqlDataReader dr = objCtrTest.llenarTablaTest();
            dgvTest.ColumnCount = 2;
            dgvTest.Columns[0].Name = "Pregunta";
            dgvTest.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvTest.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvTest.Columns[1].Name = "idpregunta";
            dgvTest.Columns[1].Visible = false;
            dgvTest.Rows.Clear();

            while (dr.Read())
            {
                dgvTest.Rows.Add(dr.GetString(1), dr.GetInt32(0));
            }

            this.dgvTest.CellClick += (this.dgvTest_Click);
        }

        private void dgvTest_Click(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = e.RowIndex;
            if (rowIndex >= 0)
            {
                txtTestNombre.Text = dgvTest.Rows[rowIndex].Cells[0].Value.ToString();
                lblIdTest.Text = dgvTest.Rows[rowIndex].Cells[1].Value.ToString();
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            objAgrpregunta.LlenarTablaPregunta();
            objAgrpregunta.LLenarCmoCategorias();
            objAgrpregunta.Show();
            this.Hide();
        }

        private void btnGuardarTest_Click_1(object sender, EventArgs e)
        {
            if (this.objCtrTest.validarCaja(txtTestNombre))
            {
                this.objCtrTest.insertarTest(txtTestNombre, lblIdTest, LblIdDoctor);
                this.txtTestNombre.Clear();
                this.llenarTablaTest();
            }
        }

        private void btnEliminarTest_Click_1(object sender, EventArgs e)
        {
            if (this.objCtrTest.validarBaja(txtTestNombre, lblIdTest))
            {
                this.objCtrTest.bajaTest(txtTestNombre, lblIdTest);
                this.txtTestNombre.Clear();
                this.lblIdTest.Text = "";
                this.llenarTablaTest();
            }
        }

        private void btnLimpiarTest_Click_1(object sender, EventArgs e)
        {
            this.txtTestNombre.Clear();
            this.lblIdTest.Text = "";
        }


        
    }
}
